import os
from building import *

cwd = GetCurrentDir()

Import('asenv')
MODULES = asenv['MODULES']
BOARD = asenv['BOARD']
ASROOT = asenv['ASROOT']
RELEASE = asenv['RELEASE']

objs = []

if('DCM' in MODULES):
    if('DCM_MINI' in MODULES):
        objs += Glob('Dcm/DcmMini.c')
    else:
        objs += Glob('Dcm/*.c')
        SrcRemove(objs, ['DcmMini.c'])
    asenv.Append(CPPPATH=['%s/Dcm/inc'%(cwd)])

if('DEM' in MODULES):
    objs += Glob('Dem/*.c')

if('DET' in MODULES):
    objs += Glob('Det/*.c')

if((BOARD=='posix') and IsPlatformWindows()):
    gcc = asenv['CC']
    binutils = os.path.abspath('%s/../lib/binutils'%(gcc.split(' ')[0][:-3]))
    target = '%s/release/%s/backtrace.dll'%(ASROOT,RELEASE)
    cmd = '%s -O2 -shared -Wall -D__ASDEBUG_BACKTRACE__ -o %s' \
        ' %s/Det/backtrace.c -lbfd -lintl -liberty -limagehlp -lz -L%s'%(
            gcc, target, cwd, binutils)
    MKObject(Glob('Det/backtrace.c'), target, cmd, False)

Return('objs')
